var api = require("../../../utils/api.js"), 
util = require("../../../utils/util.js"),
app = getApp();
Page({
    data: {
        active:0,
        childrenActive:-1,
        serBannerList: [],
        proBannerList: [],
        serTabList: [],
        proTabList: [],
        serTab: "",
        serTabNum: 0,
        proTab: "",
        proTabNum: 0,
        serList: [],
        proList: [],
        childTabList: [],
        pageIndex: 1,
        pageSize: 10,
        serEmpty: !1,
        proEmpty: !1,
        serScroll: !0,
        proScroll: !0,
        isFirst: !0,
        baseImgUrl:app.globalData.baseImgUrl,
        show:false,
        bangsHeight:wx.getStorageSync('navBarObj').bangsHeight,
    },
    onLoad: function(t) {
        this.setData({pageIndex:1,cate_id:t.id})
        this.getArticleList();
    },
    async getBannerList() {
        let {data}=await api.default.getBanner();
        this.setData({bannerList:Array.isArray(data)?data:[]})
    },
    async getArticleList() {
        let param={
            pageIndex:this.data.pageIndex,
            cate_id:this.data.cate_id,
            pageSize:this.data.pageSize
        }
        let {data:{list,total}}=await api.default.articleList(param);
        let listArr=Array.isArray(list)?list:[];
        listArr.forEach(item=>{
          item.create_time = util.formatTime2(new Date(item.create_time*1000))
        })
        this.setData({
            proScroll:listArr.length<=this.data.pageSize?true:false,
            proList: this.data.pageIndex==1?listArr:[...this.data.proList,...listArr],
            serEmpty:total==0?true:false
        })
    },
    toDetailPage: function(t) {
        if(t.currentTarget.dataset.type == 0)return;
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "./articleDetail?id=" + a
        })
    },
    toBannerDetail: function (e) {
      if (e.currentTarget.dataset.type == 0) return;
      wx.navigateTo({
        url: '/pages/home/bannerDetail/bannerDetail?id=' + e.currentTarget.dataset.id,
      })
    },
    onClose(){
        this.setData({show:false})
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            pageIndex: 1,
            pageSize: 10,
            proList: [],
            serScroll: true,
        }), this.getServerList();
    },
    onReachScrollBottom: function() {
        this.data.serScroll && 
        this.setData({
            pageIndex: this.data.pageIndex + 1
        }), this.getArticleList()
    },
    onShareAppMessage(e){
      return  util.shareEvent(e)
    }
});